import pygame
from pygame.sprite import Sprite


class Bullet(Sprite):
    """子弹类"""

    def __init__(self, ai_settings, screen, ship, img_role):
        super(Bullet, self).__init__()
        self.screen = screen
        if img_role == 1:
            self.bullet_img = pygame.image.load("./images/bullet_img.png")
        elif img_role == 2:
            self.bullet_img = pygame.image.load("./images/moon_bullet.png")

        self.rect = self.bullet_img.get_rect()
        self.rect.centerx = ship.rect.centerx
        self.rect.top = ship.rect.top

        self.y = float(self.rect.y)

        self.speed_factor = ai_settings.bullet_speed_factor

    def update(self):

        self.y -= self.speed_factor

        self.rect.y = self.y

    def draw_bullet(self):
        """将子弹绘制到屏幕上。"""
        # pygame.draw.rect(self.screen, self.color, self.rect)
        self.screen.blit(self.bullet_img, self.rect)
